package com.niiwoo.civet.trade.report.upload.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.cert.CertificateException;

/**
 * 
 * @author Administrator
 *
 */
public class CertificateUtil {
	
	/**
	 *
	 * @param cerFilePath 
	 * @return
	 * @throws IOException 
	 * @throws CertificateException
	 */
	  public static String getSignCert(String enterpriseCerFilePath) throws IOException
	  {
		  FileInputStream fileInputStream = null;
		  InputStreamReader inputStreamReader = null;
		  BufferedReader bufferedReader = null;
		  try{
			  File filename = new File(enterpriseCerFilePath); //
			  fileInputStream = new FileInputStream(filename);
	          inputStreamReader = new InputStreamReader(fileInputStream); //
	          bufferedReader = new BufferedReader(inputStreamReader); //
	          StringBuffer stringBuffer = new StringBuffer();
	          String line= bufferedReader.readLine().trim();
	          while (line != null) {  
	        	  stringBuffer.append(line);  
	              line = bufferedReader.readLine(); //
	          }
	          return stringBuffer.toString();
		  }catch(IOException ioe){
			  ioe.printStackTrace();
			  throw ioe;
		  }finally{
			  if(null != bufferedReader) bufferedReader.close();
			  if(null != inputStreamReader) inputStreamReader.close();
			  if(null != fileInputStream) fileInputStream.close();
		  }
	  }
	  
	  public static void main(String[] args) throws Exception{
		  CertificateUtil util = new CertificateUtil();
		  String strUsetcer = CertificateUtil.getSignCert("D:\\workspace\\niiwoo\\civet-2018\\civet-trade-impl\\src\\main\\resources\\signcert\\niiwoo-jrb.cer");
		  System.out.println("strUsetcer:"+strUsetcer);
	  }
}
